var datatable;// 定义一个全局的dataTable
var beginDateTemp;
var endDateTemp;
var dateTypeTemp;
var queryCond;
var interfaceType;

$(function() {
	getList();
});

function getList() {
	var dateType=$("#dateType").val().trim();
	var beginDate=$("#beginDate").val().trim();
	var endDate=$("#endDate").val().trim();
	var interfaceType=$("#interfaceType").val().trim();
	var procedureType=$("#procedureType").val().trim();
	var failureType=$("#failureType").val().trim();
	 
	$("#table tbody tr").remove();
	if (datatable == undefined || datatable == "undefined" || datatable == null) {
	} else {
		datatable.fnDestroy();
	}
	datatable = $('#table')
			.dataTable(
					{
						"bPaginate" : true, // 翻页功能
						"bLengthChange" : false, // 改变每页显示数据数量
						"bFilter" : false, // 过滤功能
						"bSort" : false, // 排序功能
						"bInfo" : true,// 页脚信息
						"bAutoWidth" : true,// 自动宽度
						 "fnDrawCallback": function (oSettings) {
							 },
						// "sPaginationType": "full_numbers",//显示分页的样式 还有simple_numbers等
						"sScrollX" : "100%",
						"sScrollXInner": "110%",
						"iDisplayLength" : 50,
						"bScrollCollapse" : true,
						"oLanguage" : {
							"sLengthMenu" : "每页显示 _MENU_条",
							"sZeroRecords" : "没有找到符合条件的数据",
							"sProcessing" : "&nbsp;&nbsp;&nbsp;&nbsp;查询中，请稍等...",
							"sInfo" : "当前第 _START_ - _END_ 条　共计 _TOTAL_ 条",
							"sInfoEmpty" : "没有记录",
							"sInfoFiltered" : "(从 _MAX_ 条记录中过滤)",
							"sSearch" : "搜索：",
							"oPaginate" : {
								"sFirst" : "首页",
								"sPrevious" : "前一页",
								"sNext" : "后一页",
								"sLast" : "尾页"
							}
						},
						"bProcessing" : true,
						"bServerSide" : true,
						"sAjaxSource" : "../../kpi/userFailureLink/getList",
						"fnServerData" : function(sSource, aoData, fnCallback) {
							$.ajax({
								"type" : "post",
								"contentType" : "application/x-www-form-urlencoded",
								"url" : sSource,
								"dataType" : "json",
								"data" : {
									"aoData" : JSON.stringify(aoData),
									"dateType":dateType,
									"interfaceType" : interfaceType,
									"beginDate" : beginDate,
									"endDate" : endDate,
									"procedureType" : procedureType,
									"failureType" : failureType,
									"failureTypeInfo" : $("#failureTypeInfo").val(),
									"jspType" : $("#jspType").val(),
									"queryCond" : $("#queryCond").val(),
									"city_code" : $("#city_code").val(),
									"enodeb_id" : $("#enodeb_id").val(),
									"cell_name" : $("#cell_name").val(),
									"terminal_model" : $("#terminal_model").val(),
									"terminal_brand" : $("#terminal_brand").val(),
									"msisdn" : $("#msisdn").val(),
									"imsi" : $("#imsi").val(),
									"apn" : $("#apn").val()
								}, // 以json格式传递
								"success" : function(resp) {
									var status=resp.status;
									if(status!="0"){
										alert(resp.msg);
									}
									fnCallback(resp.pageDate);
								}
							});
						},
						columns : [ {
							data : "report_date"
						}, {
							data : "msisdn"
						}, {
							data : "imsi"
						}, {
							data : "imei"
						}, {
							data : "city_code"
						}, {
							data : "terminal_model"
						}, {
							data : "apn"
						}, {
							data : "failure_count",
							render : function(value,type,row){
								var	url = "<a href='#' onclick=\"failureCountDetail('"
											+ row.report_date + "','"
											+ row.imsi + "','"
											+"')\"  >"+ value + "</a>";
								return url;
							}
						}]
					});

}
function failureCountDetail(report_date,imsi){
	var jspType = $("#jspType").val();
	var interfaceType = $("#interfaceType").val();
	var failureType = $("#failureType").val();
	var dateType = $("#dateType").val();
	var failureDetailQueryCond = $("#failureDetailQueryCond").val();
	var procedureType = $("#procedureType").val();
	var url="/kpi/failureDetail/index?beginDate="+report_date+"&endDate="+report_date+"&imsi="+imsi+"&jspType="+jspType+"&procedureType="+procedureType
	if(jspType == 'interfaceFailStatisticsForCell'){
		var city_code = $("#city_code").val();
		var enodeb_id = $("#enodeb_id").val();
		var cell_name = $("#cell_name").val();
		url += "&city_code="+city_code+"&enodeb_id="+enodeb_id+"&cell_name="+cell_name
	}else if(jspType == 'interfaceFailStatisticsForTerminal'){
		var terminal_model = $("#terminal_model").val();
		var terminal_brand = $("#terminal_brand").val();
		url +="&terminal_brand="+terminal_brand+"&terminal_model="+terminal_model
	}else if(jspType == 'interfaceFailStatisticsForArea'){
		var city_code = $("#city_code").val();
		url += "&city_code="+city_code
	}else if(jspType == 'interfaceFailStatisticsForUser'){
		var city_code = $("#city_code").val();
		var msisdn = $("#msisdn").val();
		var imsi = $("#imsi").val();
		url +="&city_code="+city_code+"&msisdn="+msisdn+"&imsi="+imsi
	}else if(jspType == 'interfaceFailStatisticsForApn'){
		var apn = $("#apn").val();
		url +="&apn="+apn
	}
	url += "&interfaceType="+interfaceType+"&failureType="+failureType+"&dateType="+dateType+"&failureDetailQueryCond="+failureDetailQueryCond;
	linkTab("故障详单",url);
}
